﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InfoPick.Lib.Entity;
using System.Configuration;

namespace InfoPick.Lib.DataProvider
{
    public class DataProviderFactory
    {
        private static readonly string logFile = ConfigurationManager.AppSettings["LogFile"];

        private static bool LogFile
        {
            get
            {
                if (logFile == "true")
                    return true;
                return false;
            }
        }

        public static IDataProvider GetDataProvider(Server mgw, Server msc, string mgwPath = null, string mscPath = null)
        {
            IDataProvider provider = null;
            if (mgw != null && msc != null)
            {
                provider = new TelnetProvider(mgw, msc);
            }
            else if (!string.IsNullOrEmpty(mgwPath) && !string.IsNullOrEmpty(mscPath))
            {
                provider = new TextProvider(mgwPath, mscPath);
            }

            if (provider != null)
            {
                if (LogFile)
                {
                    string tempPath = Global.TelnetTempDir;
                    return new LogFileProvider(tempPath, provider);
                }
                else
                {
                    return provider;
                }
            }

            throw new Exception("初始化Provicer错误，参数错误！");
        }
    }
}
